package zhongbo.java.air.flightpath.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.Topic;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import zhongbo.java.air.flightpath.listener.RedisIngestionListener;
import zhongbo.java.air.flightpath.listener.RedisSubscribeLogChanelListener;


/**
 * @author WeiJin
 * @version 1.0
 * @since 2025/4/2 9:13
 */
@Configuration
@Slf4j
public class RedisListenerConfig {

    /**
     * 日志消息频道
     */
    public static final String LOG_CHANEL = "log_chanel_wei_jin";
    /**
     * 接引日志消息频道
     */
    public static final String INGESTION_FLIGHT_PATH = "ingestion_flight_path_wei_jin";

    /**
     * 配置redis listenerContainer监听容器，添加logChanelListener 监听器到容器里，同时说指定频道
     *
     * @param listenerContainer 注入listenerContainer （在common模块配置了bean）
     * @param logChanelListener redis日志频道监听器
     */
    @Autowired
    public void configListener(RedisMessageListenerContainer listenerContainer,
                               RedisSubscribeLogChanelListener logChanelListener,
                               RedisIngestionListener redisIngestionListener) {
        log.info("配置redis 日志监听器");
        Topic topic = new PatternTopic(LOG_CHANEL);
        listenerContainer.addMessageListener(logChanelListener, topic);

        Topic ingestionTopic = new PatternTopic(INGESTION_FLIGHT_PATH);
        // 将接引监听器配置到容器里
        listenerContainer.addMessageListener(redisIngestionListener, ingestionTopic);

    }

    /**
     * 配置redis listenerContainer监听容器，添加redisIngestionListener 监听器到容器里，同时说指定频道
     *
     * @param listenerContainer      监听器容器
     * @param redisIngestionListener 接引监听器
     */
    // @Autowired
    // public void configIngestionListener(RedisMessageListenerContainer listenerContainer,
    //                                     RedisIngestionListener redisIngestionListener) {
    //     log.info("配置redis ingestion监听器");
    //     Topic topic = new PatternTopic(INGESTION_FLIGHT_PATH);
    //     // 将接引监听器配置到容器里
    //     listenerContainer.addMessageListener(redisIngestionListener, topic);
    // }
}
